package com.example.cuilei.kblight.util;

import android.app.Service;
import android.content.Context;
import android.content.SharedPreferences;

import com.example.cuilei.kblight.R;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Created by Lay on 2014/12/11.
 */
public class PreferencesUtil {

    private static SharedPreferences preferences;
    private static SharedPreferences.Editor editor;

    public static Map<String, String> get(Context context) {
        String[] array = context.getResources().getStringArray(R.array.preferences);
        Map<String, String> map = new HashMap<String, String>();
        String v = null;
        for (String preference : array) {
            v = context.getSharedPreferences(context.getString(R.string.preferenceName), 1).getString(preference, null);
            if (v != null && !"".equals(v))
                map.put(preference, v);
        }

        return map;
    }

    public static void put(Context context, Map<String, String> map) {
        editor = context.getSharedPreferences(context.getString(R.string.preferenceName), 1).edit();
        for (Map.Entry<String, String> m : map.entrySet()) {
            editor.putString(m.getKey(), m.getValue());
        }
        editor.commit();
    }

    public static Map<String, String> closeLight() {
        Map<String, String> ps = new HashMap<String, String>();
        ps.put("isOpen", "false");
        return ps;
    }

    public static Map<String, String> openLight() {
        Map<String, String> ps = new HashMap<String, String>();
        ps.put("isOpen", "true");
        return ps;
    }

}
